package com.nuo.common.web.util;

import cn.hutool.core.util.IdUtil;
import com.nuo.common.core.constant.TraceLogConstants;
import org.slf4j.MDC;

/**
 * trace 工具类
 * @author LGC
 */
public class TraceIdUtil {

    public static String getTraceId() {
        String traceId = MDC.get(TraceLogConstants.TRACE_ID);
        return traceId == null ? generateTraceId() : traceId;
    }

    public static void setTraceId(String traceId) {
        MDC.put(TraceLogConstants.TRACE_ID, traceId);
    }

    public static void remove() {
        MDC.remove(TraceLogConstants.TRACE_ID);

    }

    public static void clear() {
        MDC.clear();
    }

    public static String generateTraceId() {
        return IdUtil.fastSimpleUUID();
    }
}
